package com.mazihao.emos.common.util;

import org.apache.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

public class AjaxResult extends HashMap<String, Object> {
    public AjaxResult() {
        put("code", HttpStatus.SC_OK);
        put("msg", "success");
    }

    public static AjaxResult error() {
        AjaxResult result = new AjaxResult();
        result.put("code", HttpStatus.SC_INTERNAL_SERVER_ERROR);
        result.put("msg", "未知异常，请联系管理员");
        return result;
    }

    public static AjaxResult error(String msg) {
        AjaxResult result = new AjaxResult();
        result.put("code", HttpStatus.SC_INTERNAL_SERVER_ERROR);
        result.put("msg", msg);
        return result;
    }

    public static AjaxResult error(int code, String msg) {
        AjaxResult result = new AjaxResult();
        result.put("code", code);
        result.put("msg", msg);
        return result;
    }

    public static AjaxResult ok(String msg) {
        AjaxResult result = new AjaxResult();
        result.put("msg", msg);
        return result;
    }

    public static AjaxResult ok(Map<String, Object> map) {
        AjaxResult result = new AjaxResult();
        result.putAll(map);
        return result;
    }

    public static AjaxResult ok() {
        return new AjaxResult();
    }

    @Override
    public AjaxResult put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
